﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TiecCuoi
{
    public partial class Form1 : Form
    {
        bool _ISClose = false;
        public Form1()
        {
            InitializeComponent();
            //ket noi SQL
            KetNoiSQL();

        }

        //----------------------Xu Kien Shortcuts---------------------------------
        private void lvShortcuts_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            switch (lvShortcuts.Items[lvShortcuts.FocusedItem.Index].SubItems[0].Text)
            {
                case "Đặt Tiệc"://1

                    _Index = 1;
                    DatTiec formdattiec = new DatTiec(_CNN);
                    formdattiec.ShowDialog();
                    break;
                case "Loại Sảnh"://2

                    _Index = 2;
                    //Hien thi child button
                    P_ChildButton.Location = new Point(272, 0);
                    P_ChildButton.Visible = true;
                    break;
                case "Sảnh":    //3

                    _Index = 3;
                    //Hien thi child button
                    P_ChildButton.Location = new Point(372, 3);
                    P_ChildButton.Visible = true;
                    break;
                case "Món Ăn":  //4

                    _Index = 4;
                    //Hien thi child button
                    P_ChildButton.Location = new Point(485, 3);
                    P_ChildButton.Visible = true;
                    break;
                case "Dịch Vụ": //5
 
                    _Index = 5;
                    //Hien thi child button
                    P_ChildButton.Location = new Point(155, 109);
                    P_ChildButton.Visible = true;
                    break;
                case "Tra Cứu": //6

                    //_Index = 6;
                    ////Hien thi child button
                    //P_ChildButton.Location = new Point(270, 109);
                    //P_ChildButton.Visible = true;
                    TraCuu formtracuu = new TraCuu(_CNN);
                    formtracuu.ShowDialog();
                    break;
                case "Doanh Thu": //7

                    _Index = 7;
                    //Hien thi child button
                    //P_ChildButton.Location = new Point(372, 109);
                    //P_ChildButton.Visible = true;
                    DoanhThu formdoanhthu = new DoanhThu(_CNN);
                    formdoanhthu.ShowDialog();
                    break;
                case "Thoát"://8

                    _Index = 8;
                    this.Close();
                    break;

            }
        }
        //--------------------------------------------------------------
        //**********
        //-----------------Cac xu kien Child buton-------------------
        private void btn_Add_Click(object sender, EventArgs e)//---ADD--1
        {
            //Lose Child button
            P_ChildButton.Visible = false;
            _ChildIndex = 1;
            //dua vao _Index + _ChildIndex de tao Form
            switch(_Index)
            {
                case 1://---------------------------------Tiec Cuoi

                    break;
                case 2://----------------------------------Loai sanh
                    FormLoaiSanh formloaisanh = new FormLoaiSanh(_CNN, true);
                    formloaisanh.ShowDialog();
                    break;
                case 3://-------------------------------------Sanh
                    FormSanh formsanh = new FormSanh(_CNN, true);
                    formsanh.ShowDialog();
                    break;
                case 4://------------------------------------Mon an
                    FormMonAn formMonAn = new FormMonAn(_CNN, true);
                    formMonAn.ShowDialog();
                    break;
                case 5://------------------------------------dich vu
                    FormDV formdv = new FormDV(_CNN, true);
                    formdv.ShowDialog();
                    break;
                case 6://---------------------------------------Tra cuu
                    break;
                case 7://----------------------------------------Hoa don
                    break;
                case 8://-----------------------------------------Doanh thu
                    break;
            }


        }

        private void btn_Modify_Click(object sender, EventArgs e)//---EDIT--2
        {
            //Lose Child button
            P_ChildButton.Visible = false;
            _ChildIndex = 2;
            //dua vao _Index + _ChildIndex de tao Form
            switch (_Index)
            {
                case 1://---------------------------------Tiec Cuoi

                    break;
                case 2://----------------------------------Loai sanh
                    FormLoaiSanh formloaisanh = new FormLoaiSanh(_CNN, false);
                    formloaisanh.ShowDialog();
                    break;
                case 3://-------------------------------------Sanh
                    FormSanh formsanh = new FormSanh(_CNN, false);
                    formsanh.ShowDialog();
                    break;
                case 4://------------------------------------Mon an
                    FormMonAn formMonAn = new FormMonAn(_CNN, false);
                    formMonAn.ShowDialog();
                    break;
                case 5://------------------------------------dich vu
                    FormDV formdv = new FormDV(_CNN, false);
                    formdv.ShowDialog();
                    break;
                case 6://---------------------------------------Tra cuu
                    break;
                case 7://----------------------------------------Hoa don
                    break;
                case 8://-----------------------------------------Doanh thu
                    break;
            }
        }

        private void btn_Close_Click(object sender, EventArgs e)//---Close--3
        {   
            //Lose Child button
            P_ChildButton.Visible = false;
            //reset _ChildIndex
            _ChildIndex = 0;

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_ISClose == false && MessageBox.Show("Are you sure to exit?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
                DialogResult.No)
            {
                e.Cancel = true;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Login login = new Login(_CNN);
            login.ShowDialog();
            if (login.Flag == false)
            {
                _ISClose = true;
                this.Close();

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DoiPass form = new DoiPass(_CNN);
            form.ShowDialog();
        }
        //---------------------------------------------------------------
        //***********
        //-----------------------
    }
}
